<?php

namespace app\web\controller;

use app\common\model\Activity as ActivityModel;
use app\common\model\ActivityItem;
use app\common\model\ActivityItemViper;
use app\common\service\ActivityService;
use app\common\service\FeiEHttpClient;
use app\common\service\FeiEPrintService;
use app\web\validate\ActivityValidate;
use plugins\FeiE\FeiEPrintClass;
use think\Db;


/**
 * 设置活动
 * Class FeiEPrintConfig
 * @package app\manage\admin
 */
class FeiEPrintConfig extends Auth
{

    /**
     * 添加打印机
     */
    public function addPrinterList (){

        if ($this->request->isPost()) {
            // 表单数据
            $post = $this->request->post();
            $print_class = new FeiEPrintClass();

            //打印机编号SN(必填) # 打印机识别码KEY(必填) # 备注名称(选填) # 流量卡号码(选填)，多台打印机请换行（\n）添加新打印机信息，每次最多100行(台)。
            //$printerContent = !empty($post['content']) ? $post['content'] : "570802565 # 3kpsur5v # 测试打印2\n";
            //$printerContent = $post['sn'] . ' # ' . $post['ukey'] . ' # ' . $post['remarks']. ' # ' .$post['card'];
            $printerContent = '';
            if (!empty($post['sn'])) $printerContent .= $post['sn'];
            if (!empty( $post['ukey']))  $printerContent .= ' # ' . $post['ukey'];
            if (!empty( $post['remarks']))  $printerContent .= ' # ' .$post['remarks'];
            if (!empty( $post['card']))   $printerContent .= ' # '. $post['card'];

            $result = $print_class->printerAddlist($printerContent);
            $result = json_decode($result,true);
            if ($result['ret'] == 0) {
                if (empty($result['data']['no'])) {
                    $post['store_id'] = $this->userInfo['store_id'];
                    Db::name('qt_store_printer')->insert($post);
                }
                $this->result('操作成功', $result['data'], 200);
            }else {
                $this->result('操作成功', $result['msg'], 200);
            }

        }
        $this->result('无效的请求', '', 204);

    }



}